package com.dq.eduservice.controller;

import com.dq.commonutils.vo.Result;
import com.dq.eduservice.entity.EduChapter;
import com.dq.eduservice.service.EduChapterService;
import com.dq.eduservice.vo.chapter.ChapterVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

/**
 * 章节
 * $tableInfo.name-API
 * @author Dq
 * @since 2022-07-22 19:50:35
 */
@RestController
@RequestMapping("eduservice/chapter")
public class EduChapterController {

    @Autowired
    private EduChapterService chapterService;

    /**
     * 根据课程Id查询章节小节
     * @param courseId
     * @return
     */
    @GetMapping("getChapterAndVideo/{courseId}")
    public Result getChapterAndVideo(@PathVariable String courseId){
        List<ChapterVo> chapterVoList = chapterService.getChapterAndVideoByCourseId(courseId);
        HashMap<String, List<ChapterVo>> map = new HashMap<>();
        map.put("allChapterVideo",chapterVoList);
        return Result.success(map);
    }

    /**
     * 单一添加章节
     * @param eduChapter
     * @return
     */
    @PostMapping("addChapterInfo")
    public Result addChapter(@RequestBody EduChapter eduChapter){
        chapterService.addChapter(eduChapter);
        return Result.success(null);
    }

    /**
     * 根据章节Id查询章节
     * @return
     */
    @GetMapping("getChapterInfo/{chapterId}")
    public Result getChapterById(@PathVariable String chapterId){
        ChapterVo chapterVo=chapterService.getChapterById(chapterId);
        return Result.success(chapterVo);
    }

    /**
     * 修改章节对象
     * @param eduChapter
     * @return
     */
    @PostMapping("updateChapterInfo")
    public Result updateChapterInfo(@RequestBody EduChapter eduChapter){
        chapterService.updateChapterInfo(eduChapter);
        return Result.success(null);
    }

    /**
     * 根据章节id删除对应章节 小节
     * @param chapterId
     * @return
     */
    @PostMapping("deleteChapterInfoAndVide/{chapterId}")
    public Result deleteChapterInfoAndVideoById(@PathVariable String chapterId){
        chapterService.deleteChapterInfoAndVideoById(chapterId);
        return Result.success(null);
    }
}